//加工入库结算 添加 详情
<template>
    <!-- 集采汇总编辑页 -->
    <div class="e-form">
        <BillTop title="加工入库结算详情" @cancel="handleClose"></BillTop>
        <!-- //详情 添加页面 ↓ -->
        <div>
            <div class="tabs">
                <el-tabs
                    tab-position="left"
                    v-model="tabsName"
                    @tab-click="onChangeTab"
                >
                    <!-- 基本信息 -->
                    <el-tab-pane
                        label="基本信息"
                        name="baseInfo"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>
                    <el-tab-pane
                        label="结算明细"
                        name="planDetail"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>

                    <el-tab-pane
                        label="服务费用"
                        name="fwfy"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>

                    <el-tab-pane
                        label="保证金"
                        name="bzj"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>

                    <el-tab-pane
                        label="差价列表"
                        name="cjlb"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>

                    <el-tab-pane
                        label="附件信息"
                        name="accessory"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>

                    <el-tab-pane
                        label="审核历史"
                        name="auditHistory"
                        :disabled="clickTabFlag"
                    ></el-tab-pane>

                    <!-- <el-tab-pane
          label="审核历史"
          name="auditHistory"
          :disabled="clickTabFlag"
        ></el-tab-pane> -->
                    <div>
                        <!-- 基本信息 -->
                        <div id="baseInfoCon" class="con">
                            <div class="e-form">
                                <div class="tabs">
                                    <div class="tabs-title" id="baseInfo">
                                        基本信息
                                    </div>
                                    <div style="width: 100%" class="form">
                                        <el-form
                                            ref="rulesBaseRef"
                                            :rules="rulesBase"
                                            :model="formData"
                                            label-width="150px"
                                        >
                                            <el-row>
                                                <el-col
                                                    :span="12"
                                                    v-if="Thewas != 'add'"
                                                    prop="billNo"
                                                >
                                                    <el-form-item
                                                        label="结算编号："
                                                    >
                                                        <span>{{
                                                            formData.billNo
                                                        }}</span>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="单据机构："
                                                        prop="orgName"
                                                    >
                                                        <span>{{
                                                            formData.orgName
                                                        }}</span>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="是否计加工费："
                                                        prop="isIncludingProcessingFee"
                                                    >
                                                        <el-radio-group
                                                            v-model="
                                                                formData.isIncludingProcessingFee
                                                            "
                                                            disabled
                                                        >
                                                            <el-radio :label="1"
                                                                >是(外部加工)</el-radio
                                                            >
                                                            <el-radio :label="0"
                                                                >否(自行加工)</el-radio
                                                            >
                                                        </el-radio-group>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="加工合同："
                                                        prop="contractName"
                                                    >
                                                        <span>{{
                                                            formData.contractName
                                                        }}</span>
                                                        <i
                                                            slot="suffix"
                                                            class="
                                                                el-input__icon
                                                                el-icon-document-copy
                                                            "
                                                            @click="ccht"
                                                            v-show="
                                                                formData.contractBillId
                                                            "
                                                        ></i>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="加工单位："
                                                        prop="processingUnitName"
                                                    >
                                                        {{
                                                            formData.processingUnitName
                                                        }}
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="原材料来源："
                                                        prop="materialSource"
                                                    >
                                                        <span>{{
                                                            formData.materialSource
                                                        }}</span>
                                                        <!-- <el-input :disabled="true" v-model="formData.materialSource"></el-input> -->
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="收料类型："
                                                        prop="receivingType"
                                                    >
                                                        <el-radio-group
                                                            v-model="
                                                                formData.receivingType
                                                            "
                                                            disabled
                                                        >
                                                            <el-radio :label="0"
                                                                >普通加工</el-radio
                                                            >
                                                            <el-radio :label="1"
                                                                >砼加工</el-radio
                                                            >
                                                        </el-radio-group>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <!-- 返回id、名字 -->
                                                    <el-form-item
                                                        label="结算日期："
                                                        prop="settlementDate"
                                                    >
                                                        {{
                                                            formData.settlementDate
                                                        }}
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="加工费(元)："
                                                        prop='processCost'
                                                    >
                                                        {{
                                                            formData.processCost
                                                        }}
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="录入人员："
                                                        prop="entryPersonnelName"
                                                    >
                                                        <span>{{
                                                            formData.entryPersonnelName
                                                        }}</span>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>

                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="税率%："
                                                        prop="taxRate"
                                                    >
                                                        {{ formData.taxRate }}
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="税价合计："
                                                        prop='totalAmount'
                                                    >
                                                        <span>{{
                                                            formData.totalAmount
                                                        }}</span>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>

                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="税额："
                                                        prop='taxAmount'
                                                    >
                                                        <span>{{
                                                            formData.taxAmount
                                                        }}</span>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="累计结算金额："
                                                    >
                                                        <span>{{
                                                            formData.cumulativeSettlementAmount
                                                        }}</span>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>

                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="发票编号："
                                                        prop="invoiceNo"
                                                    >
                                                        {{ formData.invoiceNo }}
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="税额差额(元)："
                                                    >
                                                        <span>{{
                                                            formData.taxDifference
                                                        }}</span>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>

                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="服务费用(含税,元)："
                                                        prop='freight'
                                                    >
                                                        <span>{{
                                                            formData.freight
                                                        }}</span>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="终期结算："
                                                    >
                                                        <el-checkbox
                                                            v-model="
                                                                isEndSettle
                                                            "
                                                            disabled
                                                        ></el-checkbox>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>

                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="冲预付款金额(元)："
                                                    >
                                                        <el-checkbox
                                                            v-model="
                                                                isOffsetAdvancePayment
                                                            "
                                                            disabled
                                                        ></el-checkbox>
                                                        {{
                                                            formData.offsetAdvancePayment
                                                        }}
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="传财务共享"
                                                    >
                                                        {{
                                                            formData.easId
                                                                ? '已传'
                                                                : '未传'
                                                        }}
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="币种："
                                                    >
                                                        <span>{{
                                                            formData.currency
                                                        }}</span>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="本位币："
                                                        prop="baseCurName"
                                                    >
                                                        <span>{{
                                                            formData.baseCurName
                                                        }}</span>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item
                                                        label="状态："
                                                    >
                                                        <span>{{
                                                            state.find(
                                                                x =>
                                                                    x.value ==
                                                                    formData.state
                                                            ).label
                                                        }}</span>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12" v-show="formData.redBillState !== -1
                                                "
                                            >
                                                <el-form-item label="冲红单">
                                                    <span
                                                        :style="
                                                            redBillStateStyle
                                                        "
                                                        >{{
                                                            redBillStateFun
                                                        }}</span
                                                    >
                                                </el-form-item>
                                            </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item
                                                        label="备注："
                                                    >
                                                        {{ formData.remarks }}
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row
                                            v-if="
                                                formData.state === 5
                                            "
                                        >
                                            <el-col :span="12">
                                                <el-form-item label="作废人：">
                                                    <span>{{
                                                        formData.nullifyCreator
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="作废原因："
                                                >
                                                    <span>{{
                                                        formData.nullifyReason
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row
                                            v-if="
                                                formData.state === 5
                                            "
                                        >
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="作废说明："
                                                >
                                                    <span>{{
                                                        formData.nullifyDescription
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="作废时间："
                                                >
                                                    <span>{{
                                                        formData.nullifyCreated
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        </el-form>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- 结算明细 -->
                        <div id="planDetailCon" class="con">
                            <div class="tabs-title" id="planDetail">
                                结算明细
                            </div>
                            <el-tabs
                                :class="'childTab ' + childTabClass"
                                tab-position="left"
                                v-model="tabsNameChild"
                                @tab-click="onChangeTab"
                            >
                                <el-tab-pane
                                    label="加工费"
                                    name="materialDetails"
                                    :disabled="clickTabFlag"
                                ></el-tab-pane>
                                <el-tab-pane
                                    label="成品物资"
                                    name="technicalParameter"
                                    :disabled="clickTabFlag"
                                ></el-tab-pane>
                                <el-tab-pane
                                    label="原物资"
                                    name="technicalParameter2"
                                    :disabled="clickTabFlag"
                                ></el-tab-pane>
                                <div>
                                    <!-- //加工费 -->
                                    <div id="planDetailCon">
                                        <div
                                            class="tabs-title"
                                            id="materialDetails"
                                        >
                                            加工费
                                        </div>
                                        <div class="e-table">
                                            <el-table
                                                :data.sync="jgfdata"
                                                ref='jgfTable'
                                                border
                                                style="width: 100%"
                                                :row-class-name="
                                                    tableRowClassName
                                                "
                                                :tree-props="{
                                                    children: 'children',
                                                    hasChildren: 'hasChildren'
                                                }"
                                                default-expand-all
                                                row-key="uuid"
                                                v-sortTable="{ 'tableData': jgfdata, '_this': this, 'ref': 'jgfTable' }"
                                            >
                                                <el-table-column
                                                    prop="materialClassName"
                                                    label="物资类别"
                                                    width="150"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="materialName"
                                                    label="物资名称"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="spec"
                                                    label="规格"
                                                    width="200"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="texture"
                                                    label="材质"
                                                    width="200"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="unit"
                                                    label="计量单位"
                                                    width="100"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="warehouseName"
                                                    label="仓库"
                                                    width="200"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="unsettledQuantity"
                                                    label="未结算数量"
                                                    width="100"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    label="结算数量"
                                                    width="150"
                                                    prop="quantity"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="acceptancePrice"
                                                    label="验收单价(元)"
                                                    width="100"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="settlementUnit"
                                                    label="加工单价(元)"
                                                    width="100"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    label="加工费(元)"
                                                    width="150"
                                                    prop="amount"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    label="税额差额(元)"
                                                    width="150"
                                                    prop="taxDifference"
                                                >
                                                </el-table-column>
                                            </el-table>
                                        </div>
                                    </div>

                                    <!-- //成品物资 -->
                                    <div id="planDetailCon">
                                        <div
                                            class="tabs-title"
                                            id="technicalParameter"
                                        >
                                            成品物资
                                        </div>
                                        <div class="e-table">
                                            <el-table
                                                :data.sync="cpwzdata"
                                                ref='cpwzTable'
                                                border
                                                style="width: 100%"
                                                :row-class-name="
                                                    tableRowClassName
                                                "
                                                :tree-props="{
                                                    children: 'children',
                                                    hasChildren: 'hasChildren'
                                                }"
                                                default-expand-all
                                                row-key="uuid"
                                                v-sortTable="{ 'tableData': cpwzdata, '_this': this, 'ref': 'cpwzTable' }"
                                            >
                                                <el-table-column
                                                    prop="materialClassName"
                                                    label="物资类别"
                                                    width="150"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="materialName"
                                                    label="物资名称"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="spec"
                                                    label="规格"
                                                    width="200"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="texture"
                                                    label="材质"
                                                    width="200"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="unit"
                                                    label="计量单位"
                                                    width="100"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="warehouseName"
                                                    label="仓库"
                                                    width="200"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="unsettledQuantity"
                                                    label="未结算数量"
                                                    width="200"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    label="结算数量"
                                                    width="150"
                                                    prop="quantity"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="price"
                                                    label="成品单价(元)"
                                                    width="100"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="amount"
                                                    label="成品金额(元)"
                                                    width="150"
                                                >
                                                </el-table-column>

                                                <!-- <el-table-column
                                                    prop="totalAmortizationRatio"
                                                    label="总摊销比例%"
                                                    width="150"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    label="摊销时间(月)"
                                                    width="100"
                                                    prop='amortizationMonth'
                                                >
                                                </el-table-column> -->
                                            </el-table>
                                        </div>
                                    </div>

                                    <!-- //原物资 -->
                                    <div id="planDetailCon">
                                        <div
                                            class="tabs-title"
                                            id="technicalParameter2"
                                        >
                                            原物资
                                        </div>
                                        <div class="e-table">
                                            <el-table
                                                :data.sync="ywzdata"
                                                ref='ywzTable'
                                                border
                                                style="width: 100%"
                                                :row-class-name="
                                                    tableRowClassName
                                                "
                                                :tree-props="{
                                                    children: 'children',
                                                    hasChildren: 'hasChildren'
                                                }"
                                                default-expand-all
                                                row-key="uuid"
                                                v-sortTable="{ 'tableData': ywzdata, '_this': this, 'ref': 'ywzTable' }"
                                            >
                                                <el-table-column
                                                    prop="materialClassName"
                                                    label="物资类别"
                                                    width="150"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="materialName"
                                                    label="物资名称"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="spec"
                                                    label="规格"
                                                    width="200"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="texture"
                                                    label="材质"
                                                    width="200"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="unit"
                                                    label="计量单位"
                                                    width="100"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="warehouseName"
                                                    label="仓库"
                                                    width="200"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="receivedQuantity"
                                                    label="领用数量"
                                                    width="150"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    label="冲库存数量"
                                                    width="100"
                                                    prop='offsetInventoryQuantity'
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    prop="price"
                                                    label="采购单价(元)"
                                                    width="150"
                                                >
                                                </el-table-column>
                                                <el-table-column
                                                    label="金额(元)"
                                                    width="150"
                                                    prop='amount'
                                                >

                                                </el-table-column>
                                            </el-table>
                                        </div>
                                    </div>
                                </div>
                            </el-tabs>
                        </div>

                        <!-- 服务费用 -->
                        <div id="fwfyCon" class="con">
                            <div class="tabs-title" id="fwfy">服务费用</div>
                            <div class="e-table" style="min-height: auto">

                                <el-table
                                    :data="serviceFeeData"
                                    @selection-change="serviceFeeSelect"
                                    ref='serviceFeeTable'
                                    border
                                    style="width: 100%"
                                    :row-class-name="tableRowClassName"
                                    :max-height="$store.state.tableHeight"
                                    v-sortTable="{ 'tableData': serviceFeeData, '_this': this, 'ref': 'serviceFeeTable' }"
                                >
                                    <el-table-column type="selection" width="55">
                                    </el-table-column>
                                    <el-table-column
                                        label="合同编号"
                                        width="200"
                                        prop='contractBillNo'
                                        fixed
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        label="结算单位"
                                        width="200"
                                        fixed
                                        prop='settlementUnitName'
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        label="发票编号"
                                        width="200"
                                        prop='invoiceNo'
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        label="清单名称"
                                        width="200"
                                        prop='contractDtlName'
                                    >
                                    </el-table-column>
                                    <el-table-column label="数量" prop='quantity'>

                                    </el-table-column>
                                    <el-table-column
                                        prop="price"
                                        label="单价(元)"
                                    ></el-table-column>
                                    <el-table-column label="金额(元)" prop='amount'>
                                    </el-table-column>
                                    <el-table-column label="税率%" prop='taxRate'>
                                    </el-table-column>
                                    <el-table-column label="税额(元)" prop='taxAmount'>
                                    </el-table-column>
                                    <el-table-column
                                        prop="totalAmount"
                                        label="税额合计(元)"
                                        width="200"
                                    >
                                    </el-table-column>
                                </el-table>
                            </div>
                        </div>

                        <!-- 保证金 -->
                        <div id="bzjCon" class="con">
                            <div class="tabs-title" id="bzj">保证金</div>
                            <div class="lll">^ 暂扣保证金</div>
                            <div class="e-table" style="min-height: auto">
                                <el-table
                                    :data="zkbzjtableData"
                                    border
                                    style="width: 100%"
                                    v-sortTable="{ 'tableData': zkbzjtableData, '_this': this, 'ref': 'zkbzjtable' }"
                                >
                                    <el-table-column
                                        prop="returnDepositName"
                                        label="名称"
                                        width='270'
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        label="暂扣保证金(元)"
                                        width="150"
                                        prop='amount'
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        label="截止上期末暂扣保证金(元)"
                                        width="200"
                                    >
                                        <template v-slot="{ row }">
                                            {{ row.previousTotalAmount }}
                                        </template>
                                    </el-table-column>
                                    <el-table-column
                                        label="截止本期末暂扣保证金(元)"
                                        width="200"
                                    >
                                        <template v-slot="{ row }">
                                            {{ row.currentTotalAmount }}
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="说明" width="250" prop='remarks'>
                                    </el-table-column>
                                </el-table>
                            </div>
                            <div class="lll">^ 返还保证金</div>
                            <div class="e-table" style="min-height: auto">
                                <el-table
                                    :data="fhbzjtableData"
                                    ref='fhbzjtable'
                                    border
                                    style="width: 100%"
                                    v-sortTable="{ 'tableData': fhbzjtableData, '_this': this, 'ref': 'fhbzjtable' }"
                                >
                                    <el-table-column prop="returnDepositName" label="名称" width="270">
                                    </el-table-column>
                                    <el-table-column
                                        prop="amount"
                                        label="暂扣保证金(元)"
                                        width="150"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        prop="previousTotalAmount"
                                        label="截止上期末暂扣保证金(元)"
                                        width="200"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        prop="currentTotalAmount"
                                        label="截止本期末暂扣保证金(元)"
                                        width="200"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        prop="remarks"
                                        label="说明"
                                        width="250"
                                    >
                                    </el-table-column>
                                </el-table>
                            </div>
                        </div>

                        <!-- 差价列表 -->
                        <div id="cjlbCon" class="con">
                            <div class="tabs-title" id="cjlb">差价列表</div>
                            <div class="e-table" style="min-height: auto">
                                <el-table
                                    :data.sync="spreadData"
                                    ref='spreadTable'
                                    border
                                    style="width: 100%"
                                    :row-class-name="tableRowClassName"
                                    :tree-props="{
                                        children: 'children',
                                        hasChildren: 'hasChildren'
                                    }"
                                    default-expand-all
                                    row-key="uuid"
                                    v-sortTable="{ 'tableData': spreadData, '_this': this, 'ref': 'spreadTable' }"
                                >
                                    <el-table-column
                                        prop="materialClassName"
                                        label="物资类别"
                                        width="150"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        prop="materialName"
                                        label="物资名称"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        prop="spec"
                                        label="规格"
                                        width="200"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        prop="texture"
                                        label="材质"
                                        width="200"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        prop="unit"
                                        label="计量单位"
                                        width="100"
                                    >
                                    </el-table-column>
                                    <!-- <el-table-column
                                        prop="warehouseName"
                                        label="仓库"
                                        width="200"
                                    >
                                    </el-table-column> -->
                                    <el-table-column
                                        label="结算数量"
                                        width="150"
                                        prop='quantity'
                                    >

                                    </el-table-column>
                                    <el-table-column
                                        prop="acceptancePrice"
                                        label="验收单价"
                                        width="100"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        prop="price"
                                        label="加工单价(元)"
                                        width="100"
                                    >

                                    </el-table-column>
                                    <el-table-column
                                        label="加工费(元)"
                                        width="150"
                                        prop='amount'
                                    >
                                    </el-table-column>
                                    <el-table-column
                                        label="价差"
                                        width="150"
                                        prop='priceDifference'
                                    >

                                    </el-table-column>
                                </el-table>
                            </div>
                        </div>

                        <!-- 附件信息 -->
                        <div id="accessoryCon" class="con">
                            <div class="tabs-title" id="accessory">
                                附件信息
                            </div>
                            <attach-comp
                                :relationId="attachId"
                                bucketName="turnover"
                                isView
                            />
                        </div>

                        <!-- 审核历史 -->
                        <div id="auditHistoryCon" class="con">
                            <div class="tabs-title" id="auditHistory">
                                审核历史
                            </div>
                            <div class="e-table">
                                    <ComAuditHistoryIndex
                                        :billType="1022"
                                        :tableData="shenheArr"
                                        @getAuditHistory="getauditHistory"
                                    />
                            </div>
                        </div>
                    </div>
                </el-tabs>
            </div>
            <div id="seat" :style="{ height: seatHeight + 'px' }"></div>
            <div class="buttons">
                <el-button
                    type="primary"
                    style="background: #2e61d7"
                    v-if="
                        formData.state === 2 &&
                        (formData.redBillState === '' ||
                            formData.redBillState === -1)
                    "
                    @click="redSingle"
                    >冲红单</el-button
                >
                <!-- <button @click="demi1">demo</button> -->
                <exaButtons
                    :auditState="auditState"
                    @exas="exas"
                    :state="formData.state"
                    :founderId="formData.founderId"
                    v-if="formData.state !== 5"
                    :multiple="formData.state === 1 || formData.state === 2"
                    :commandList='commandList'
                >
                </exaButtons>
                <el-button @click="handleClose">关闭</el-button>
            </div>
        </div>
    </div>
</template>

<script>
import '@/utils/jquery.scrollTo.min'
import { mapMutations, mapState } from 'vuex'
import {
    showLoading,
    hideLoading,
    openAppClient,
    selectDataClient,
    showErrorPop
} from '@/utils/common'

import { getUuid } from '@/utils/common'
import AttachComp from '@/components/common/attachIndex'

import auditRequest from '@/api/materialSettlement/machiningment.js'
import publicRequest from '@/api/materialSettlement/public.js'

import ComAuditHistoryIndex from '@/pages/materialsmanagement/components/auditHistory/auditHistoryIndex'
import exaButtons from '@/components/common/exaButtons'

import { webprintReport, numToChinese } from '@/utils/common'

export default {
    components: {
        AttachComp,
        ComAuditHistoryIndex,
        exaButtons
        // historyUpdateTable
    },
    data () {
        return {
            rulesBase: {
                taxRate: [
                    {
                        required: true,
                        message: '税率不能为空',
                        trigger: 'change'
                    }
                ],
                processingUnitName: [
                    {
                        required: true,
                        message: '加工单位不能为空',
                        trigger: 'change'
                    }
                ],
                billNo: [
                    {
                        required: true,
                        message: '结算编号不能为空',
                        trigger: 'change'
                    }
                ],
                orgName: [
                    {
                        required: true,
                        message: '机构不能为空',
                        trigger: 'change'
                    }
                ],
                settlementDate: [
                    {
                        required: true,
                        message: '结算日期不能为空',
                        trigger: 'change'
                    }
                ],
                invoiceNo: [
                    {
                        required: true,
                        message: '发票编号不能为空',
                        trigger: 'change'
                    }
                ],
                baseCurName: [
                    { required: true, message: '本位币', trigger: 'change' }
                ],
                offsetAdvancePayment: [
                    { required: true, message: '冲预付款金额必填', trigger: 'chenge' }
                ],
                isIncludingProcessingFee: [
                    { required: true, message: '请选择是否计加工费', trigger: 'chenge' }
                ],
                receivingType: [
                    { required: true, message: '请选择收料类型', trigger: 'chenge' }
                ],
                processCost: [
                    { required: true, message: '请计算加工费', trigger: 'chenge' }
                ],
                entryPersonnelName: [
                    { required: true, message: '录入人员必填', trigger: 'chenge' }
                ],
                totalAmount: [
                    { required: true, message: '请计算税价合计', trigger: 'chenge' }
                ],
                taxAmount: [
                    { required: true, message: '请计算税额', trigger: 'chenge' }
                ],
                freight: [
                    { required: true, message: '请计算服务费用', trigger: 'chenge' }
                ],
            },
            //我的数据:↓
            cjlbData: [], //差价列表
            cjlbTrue: false, //控制差价列表是否显示
            nullifyParams: {
                // 作废
                billId: this.$route.query.billid,
                billType: '1022',
                nullifyDescription: '',
                nullifyReason: '',
                nullifyCreated: '',
                nullifyCreator: '',
                nullifyCreatorId: ''
            },
            Thewas: '',
            zkbzjtableData: [],
            fhbzjtableData: [],
            wzlbTableData: [],

            //验证
            yanzheng: {
                billNo: [
                    {
                        required: true,
                        message: '结算编号不能为空',
                        trigger: 'change'
                    }
                ],
                orgName: [
                    {
                        required: true,
                        message: '机构不能为空',
                        trigger: 'change'
                    }
                ],
                settlementDate: [
                    {
                        required: true,
                        message: '结算日期不能为空',
                        trigger: 'change'
                    }
                ],
                baseCurName: [
                    {
                        required: true,
                        message: '本位币不能为空',
                        trigger: 'change'
                    }
                ]
            },
            formData: {
                billNo: '', //	结算编号
                orgName: '', //机构name
                orgId: '', //机构id 不显示
                isIncludingProcessingFee: 1, //是否计加工费
                contractName: '', //合同名称
                contractBillId: '', //合同id
                contractBillNo: '', //合同编号
                processingUnitName: '', //加工单位名称
                processingUnitId: '', //加工单位 id
                materialSource: '', //原材料来源
                receivingType: 0, //收料类型 0 普通 1砼加工
                settlementDate: '', //结算日期
                processCost: 0, //加工费
                entryPersonnelName: '', //录入人员名称
                entryPersonnelId: '', //录入人员 id
                taxRate: 0, //税率
                totalAmount: 0, //税价合计
                taxAmount: 0, //税额
                cumulativeSettlementAmount: 0, //累计结算金额
                invoiceNo: '', //发票编号
                taxDifference: 0, //税额差额
                freight: 0, //运输单位费用(含税,元)
                isEndSettle: 0, //是否为终期结算 需要转成数字
                offsetAdvancePayment: 0, //冲预付款金额
                currency: '', //币种名称
                currencyId: '', //币种id
                state: '0', //状态
                baseCurName: '', //本位币名称
                baseCurId: '', //本位币id
                baseCurRate: 0, //本位币汇率
                baseCurAmount: 0, //结算金额 本位币
                remarks: '', //备注
                acceptanceBillId: '',
                acceptanceBillNo: '',
                baseCurFreight: 0,
                baseCurProcessCost: 0,
                baseCurTaxAmount: 0,
                baseCurTotalAmount: 0,
                billId: '',
                easId: '',
                evaluationLevel: '',
                founderId: '',
                founderName: '',
                gmtCreate: '',
                gmtModified: '',
                isOffsetAdvancePayment: 0,
                isRed: 0,
                nullifyCreated: '',
                nullifyCreator: '',
                nullifyCreatorId: '',
                nullifyDescription: '',
                nullifyReason: '',
                redBillState: null,
                rmbFreight: 0,
                rmbId: '',
                rmbName: '',
                rmbProcessCost: 0,
                rmbRate: 0,
                rmbTaxAmount: 0,
                rmbTotalAmount: 0,
                sourceId: '',
                sourceNumber: '',
                workId: ''
            },

            typeArr: [
                { name: '零星采购计划', id: 1 },
                { name: '物资采购合同', id: 2 },
                { name: '调拔单', id: 3 }
            ],
            viewList: true,
            paginationInfo: {
                total: 1,
                pageSize: 10,
                currentPage: 0
            },
            query: {
                beginPlanDate: '',
                endPlanDate: '',
                keyword: '',
                limit: 0,
                orgId: '',
                page: 1,
                settlementUnitId: '',
                states: []
            }, //搜索
            searchKey: '', //右上角搜索关键字
            tableData: [], //表格
            shenheArr: [],
            serviceFeeData: [],
            serviceFeeData2: [],
            serviceFeeRow: {
                amount: 0, //金额元
                billId: '',
                changeType: 1,
                contractBillId: '',
                contractBillNo: '',
                contractDtlId: '',
                contractDtlName: '',
                dtlId: '',
                invoiceNo: '',
                price: 0, //单价元
                quantity: 0, //数量
                settlementUnitId: '',
                settlementUnitName: '',
                taxAmount: 0, //税额元
                taxRate: 0, //税率%
                totalAmount: 0 // 税价合计
            },
            auditState: {},
            jgfData: [], //加工费数组
            cpwzData: [], //成品物资数组
            ywzData: [], //原物资数组
            //我的数据:↑
            tabsName: 'baseInfo',
            userName: '',
            clickId: 'baseInfo',
            tabsNameChild: '',
            childTabClass: '',
            OrgtableData: [], //申报机构数据
            OrgSonTableData: [], //申报机构子列表
            materialsTableData: [], //物资汇总数据
            auditHistoryList: [], //审核历史
            planSelect: [], //申报机构表格明细选择项
            value: '',
            textarea: '',
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            MouseEnterId: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑

            objFlag: {
                flag5: false
            },
            orgId: '', //机构id
            orgName: '', //机构名称
            billId: '',
            isSkip: false, //是否跳转
            show: true, //申报机构子列表
            dtlIds: '', //
            //验证
            rules: {
                summaryDate: [
                    {
                        required: true,
                        message: '请输入汇总日期',
                        trigger: 'blur'
                    }
                ],
                currencyId: [
                    { required: true, message: '请选择币种', trigger: 'chenge' }
                ]
            },
            materialsNameData: [], //机构汇总表
            createHistoryData: [], //明细修改历史列表
            errorMsg: [],
            isErrorMsg: true, //是否提醒错误信息
            //我的字段 ↓
            user: '', //当前用户
            //我的字段 ↑
            // 以下为接手后新增
            auditParams: {
                // 审核
                billId: this.$route.query.billid,
                billType: '1022',
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: '',
                orgId: '',
                orgName: '',
                userId: '',
                workId: ''
            },
            jsdwData: {
                businessUnitTypes: [],
                keyword: '',
                limit: 10,
                orgId: '',
                outerTypes: [],
                page: 1,
                states: [],
                type: [0, 1, 2],
                supplierTypes: [],
                subcontractorTypes: [],
                businessTypes: []
            },
            inStockList: [],
            selectStocked: '选择库存',
            selectStockQuery: {
                orgId: '',
                unitId: '',
                keyWord: '',
                stockType: '1'
            },
            isZhoucai: false,
            isRedSingle: false,
            jgfdata: [],
            ywzdata: [],
            cpwzdata: [],
            isEndSettle: 0,
            isOffsetAdvancePayment: 0,
            redBillStateStyle: {
                width: '300px',
                height: '30px',
                color: '#fff',
                backgroundColor: '',
                'text-align': 'center'
            },
            commandList: [
                { key: 1, value: '委外加工物资结算单' },
                { key: 2, value: '成品物资明细' },
                { key: 3, value: '加工物资服务费结算单' }
            ],
            spreadData: [],
            serviceFeeList: []

        }
    },
    watch: {
        // 当成品明细数组的数据发生变化时,原物资选择库存下拉框的数据也需要跟着变化
        cpwzData: {
            handler: function () {
                this.inStockList = []
                this.cpwzData.forEach(item => {
                    this.inStockList.push(...item.children.map(itm => itm))
                })
                console.log(this.inStockList)
                // 遍历成品明细,看是否有物资类别为周材的
                this.isZhoucai = this.cpwzData.some(item => {
                    return item.children.some(it => it.materialType === 1)
                })
            },
            deep: true
        },
        'formData.redBillState' () {
            if (this.formData.redBillState == 3) {
                this.redBillStateStyle.backgroundColor = '#FF2300'
            } else if (
                this.formData.redBillState == 0 ||
                this.formData.redBillState == 1
            ) {
                this.redBillStateStyle.backgroundColor = '#FFA40D'
            } else if (this.formData.redBillState == 2) {
                this.redBillStateStyle.backgroundColor = 'rgb(153,153,153)'
            }
        },
    },
    async created () {
        let data = JSON.parse(localStorage.getItem('vuex'))
        this.orgId = data.userInfo.orgInfo.orgId
        this.selectStockQuery.orgId = this.orgId
        // this.orgName = data.userInfo.orgInfo.orgName
        // this.userId = localStorage.getItem('userId')
        // this.billId = this.$route.query.billid
        // this.initData()

        this.Thewas = this.$route.query.was || 'see'
        this.user = JSON.parse(localStorage.getItem('vuex'))
        if (this.Thewas == 'add') {
            //新增的时候

            this.user = JSON.parse(localStorage.getItem('vuex'))
            this.$set(
                this.formData,
                'entryPersonnelName',
                this.user.userInfo.userName
            )
            this.$set(
                this.formData,
                'entryPersonnelId',
                this.user.userInfo.userId
            )
            this.$set(
                this.formData,
                'orgName',
                this.user.userInfo.orgInfo.orgName
            )
            this.$set(this.formData, 'orgId', this.user.userInfo.orgInfo.orgId)
        }
        this.billId = this.$route.query.billid
        this.getCurrentUnitInfo()
        this.getData()
    },
    methods: {
        ...mapMutations([
            'setPopConfirm',
            'setSelectedInfo',
            'setHistoryTableData',
            'setAuditParams'
        ]),
        getData () {
            showLoading()
            Promise.all([
                this.getBasic(),
                this.getProcessingFee(),
                this.getFinishedGoods(),
                this.getRawMaterials(),
                this.getServiceFee(),
                this.getMargin()
            ]).finally(() => {
                hideLoading()
            })
        },
        // 获取基本信息
        async getBasic () {
            this.formData = await auditRequest.getjgrk({ id: this.billId })
            this.formData.isEndSettle == 1
                ? (this.isEndSettle = true)
                : (this.isEndSettle = false)
            this.formData.isOffsetAdvancePayment == 1
                ? (this.isOffsetAdvancePayment = true)
                : (this.isOffsetAdvancePayment = false)
            let count = 0
            this.$watch('formData.taxRate', () => {
                this.jgfData.forEach(item => {
                    item.children.forEach(it => {
                        it.taxDifference = +(
                            it.amount * (this.formData.taxRate / 100) -
                            it.acceptanceTaxAmount
                        ).toFixed(2)
                    })
                    count += +item.children.reduce(
                        (prev, c) => (prev += +c.taxDifference || 0),
                        0
                    )
                })
                // 基本信息的税额差额之和
                this.formData.taxDifference = +(+count).toFixed(2)
            })
        },
        // 获取加工费
        async getProcessingFee () {
            let wzlbTableData1 = await auditRequest.getjgf({ id: this.billId })
            wzlbTableData1.forEach(item => {
                item.materialClassName = item.topClassName
                item.uuid = getUuid()
                item.isChecked = false
                item.children.forEach(i => {
                    i.uuid = i.dtlId
                    i.parentId = item.topClassId
                })
                const count = item.children
                    .reduce((prev, c) => (prev += +c.amount || 0), 0)
                    .toFixed(2)
                item.materialName = `金额小计： ${count}`
            })
            this.jgfData = wzlbTableData1
        },
        // 获取成品物资
        async getFinishedGoods () {
            let wzlbTableData2 = await auditRequest.getcpwz({
                id: this.billId
            })
            wzlbTableData2.forEach(item => {
                item.materialClassName = item.topClassName
                item.uuid = getUuid()
                item.isChecked = false
                item.children.forEach(i => {
                    i.uuid = i.dtlId
                    i.parentId = item.topClassId
                })
                const count = item.children
                    .reduce((prev, c) => (prev += +c.amount || 0), 0)
                    .toFixed(2)
                item.materialName = `金额小计： ${count}`
            })
            this.cpwzData = wzlbTableData2
        },
        // 获取原物资
        async getRawMaterials () {
            let wzlbTableData3 = await auditRequest.getywz({ id: this.billId })
            wzlbTableData3.forEach(item => {
                item.materialClassName = item.topClassName
                item.uuid = getUuid()
                item.isChecked = false
                item.children.forEach(i => {
                    i.uuid = i.dtlId
                    i.parentId = item.topClassId
                })
                const count = item.children
                    .reduce((prev, c) => (prev += +c.amount || 0), 0)
                    .toFixed(2)
                item.materialName = `金额小计： ${count}`
            })
            this.ywzData = wzlbTableData3
        },
        // 获取服务费用
        async getServiceFee () {
            this.serviceFeeData = await auditRequest.getfwfy({
                id: this.billId
            })
            if (this.serviceFeeData.data === null) {
                this.serviceFeeData = []
            }
        },
        // 获取保证金
        async getMargin () {
            this.bzjarr = await auditRequest.getbzj({ id: this.billId })
            if (this.bzjarr.length > 0) {
                for (let i = 0; i < this.bzjarr.length; i++) {
                    if (this.bzjarr[i].returnDepositType == 1) {
                        //暂扣保证金
                        this.zkbzjtableData.push(this.bzjarr[i])
                    } else {
                        //返还保证金
                        this.fhbzjtableData.push(this.bzjarr[i])
                    }
                }
            }
        },
        // 获取价差列表
        async getSpread () {
            this.spreadData = await auditRequest.getSpread(this.billId)
        },
        ccht () {
            openAppClient(
                `/processingContractApplyShow?billid=${this.formData.contractBillId}&isview=true`,
                '查看加工合同'
            )
        },

        // 加工费中的数量发生变化,联动成品物资数量变化
        quantityInput (row, str) {
            row.changeType === 1 ? (row.changeType = 1) : (row.changeType = 2)
            if (
                +row.unsettledQuantity &&
                +row.quantity > +row.unsettledQuantity
            ) {
                this.clientPop(
                    'err',
                    `不能大于未结算数量${row.unsettledQuantity}`
                )
                row.quantity = +row.unsettledQuantity
            }
            if (+row.amount && +row.quantity) {
                row.price = +(+row.amount / +row.quantity).toFixed(2)
            } else {
                row.price = 0
            }
            row.taxDifference = +(
                row.amount * (this.formData.taxRate / 100) -
                row.acceptanceTaxAmount
            ).toFixed(2)
            let count = 0
            this.jgfData.forEach(item => {
                count += +item.children.reduce(
                    (prev, c) => (prev += +c.taxDifference || 0),
                    0
                )
            })
            this.formData.taxDifference = +(+count).toFixed(2)

            // 如果加工费的数量变化,成品明细的数量也要跟着变化成一样的
            if (str === '数量') {
                let newArr = this.cpwzData.map(item => {
                    return [...item.children]
                })
                newArr.flat(Infinity).forEach(item => {
                    if (row.materialId === item.materialId) {
                        item.quantity = row.quantity
                        item.changeType === 1
                            ? (item.changeType = 1)
                            : (item.changeType = 2)
                    }
                })
            }
        },
        // 成品物资数量
        cpQuantity (row) {
            row.changeType === 1 ? (row.changeType = 1) : (row.changeType = 2)
            if (
                +row.unsettledQuantity &&
                +row.quantity > +row.unsettledQuantity
            ) {
                this.clientPop(
                    'err',
                    `不能大于未结算数量${row.unsettledQuantity}`
                )
                row.quantity = +row.unsettledQuantity
            }
            if (+row.amount && +row.quantity) {
                row.price = +(+row.amount / +row.quantity).toFixed(2)
            } else {
                row.price = 0
            }
            // 如果成品物资的数量变化,加工费的数量也要跟着变化成一样的
            let newArr = this.jgfData.map(item => {
                return [...item.children]
            })
            newArr.flat(Infinity).forEach(item => {
                if (row.materialId == item.materialId) {
                    item.quantity = row.quantity
                    item.changeType === 1
                        ? (item.changeType = 1)
                        : (item.changeType = 2)
                }
            })
        },

        // ====================================页面下方多个按钮===============================================
        //获取按钮状态
        getCurrentUnitInfo () {
            publicRequest.getCurrentUnitInfo(this.auditParams).then(res => {
                this.auditState = res
            })
        },
        //审核历史
        async getauditHistory () {
            const data = await publicRequest.getauditHistory({
                billId: this.billId,
                billType: 1022,
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: ''
            })
            this.shenheArr = data
        },
        async exas (arg) {
            if (arg === 'submit') {
                this.saveAll()
            } else if (arg === 'submitCommit') {
                if (this.cpwzData.length < 0) {
                    showErrorPop('成品物资没有进行添加,请检查！')
                    return
                }
                this.submitReview()
            } else if (arg === 'audit') {
                await this.shenhe()
            } else if (arg === 'undoAudit') {
                await this.undoAudit() // 撤销审核
            } else if (arg === 'nullify') {
                await this.nullify()
            } else if (arg === 'deleteData') {
                await this.basicInfoDelete()
            } else if (arg.type === 'multiple') {
                this.print(arg.value) // 打印
            }
        },

        // 保存所有数据
        async saveAll () {
            showLoading()
            try {
                await Promise.all([
                    this.updateBaseInfo(),
                    this.saveProcessingFee(),
                    this.saveFinishedProduct(),
                    this.saveRawMaterials(),
                    this.saveServiceFee(),
                    this.saveMargin()
                ])
                this.clientPop('suc', '保存成功')
            } catch (err) {
                console.log(err)
            } finally {
                hideLoading()
            }
        },
        // 保存并提交
        async submitReview () {
            try {
                showLoading()
                await Promise.all([
                    this.updateBaseInfo(),
                    this.saveProcessingFee(),
                    this.saveFinishedProduct(),
                    this.saveRawMaterials(),
                    this.saveServiceFee(),
                    this.saveMargin()
                ])
                await publicRequest.commitexamine(this.auditParams)
                this.clientPop('suc', '提交审核成功', this.handleClose)
            } catch (err) {
                console.log(err)
            } finally {
                hideLoading()
            }
        },
        // 审核
        shenhe () {
            try {
                this.setAuditParams(this.auditParams)
                openAppClient('/exaDialog', '填写审核意见', async () => {
                    const auditParams = JSON.parse(
                        localStorage.vuex
                    ).auditParams
                    showLoading()
                    await publicRequest.goaudit(auditParams)
                    this.clientPop('suc', '审核成功', this.handleClose)
                }, null, null, null, 'small')
            } catch (err) {
                this.clientPop('suc', '审核失败')
            } finally {
                hideLoading()
            }
        },

        // 撤销审核
        undoAudit () {
            try {
                this.clientPop('info', '确定返回上一步操作吗?', async () => {
                    showLoading()
                    await publicRequest.goBack(this.auditParams)
                    this.clientPop('suc', '撤回成功', this.handleClose)
                })
            } finally {
                hideLoading()
            }
        },
        // 作废
        nullify () {
            try {
                this.setAuditParams(this.nullifyParams)
                openAppClient('/nullifyDialog', '单据作废原因', async () => {
                    const nullifyParams = JSON.parse(
                        localStorage.vuex
                    ).nullifyParams
                    showLoading()
                    await publicRequest.zuofei(nullifyParams)
                    this.clientPop('suc', '作废成功', this.handleClose)
                }, null, null, null, 'small')
            } finally {
                hideLoading()
            }
        },
        // 删除
        basicInfoDelete () {
            this.clientPop(
                'info',
                '确定要删除吗？数据删除后不可恢复，请谨慎操作！',
                () => {
                    showLoading()
                    auditRequest
                        .deletejgrk(this.billId)
                        .then(() => {
                            this.clientPop('suc', '删除成功', this.handleClose)
                        })
                        .finally(() => {
                            hideLoading()
                        })
                }
            )
        },
        // 冲红单
        redSingle () {
            this.$router.replace({
                path: '/machiningmentAdd',
                query: { isRedSingle: '1', billid: this.billId }
            })
        },
        // 打印
        async print (value) {
            const printData = async () => {
                showLoading()
                try {
                    const params = {
                        reportTitle: '', //报表名
                        orgName: this.formData.orgName, //单据机构
                        reportQRUri: '', //报表内容URI
                        billNo: this.formData.billNo, //单据编码
                        summaryInfoItems: [],
                        tables: [] //表格
                    }
                    const reportTitle = this.commandList.find(item => item.key === value)
                    params.reportTitle = reportTitle.value
                    let tableObj = {}
                    if(reportTitle.key === 1 || reportTitle.key === 2) {
                        tableObj = {
                            1: this.ProcessingAcceptanceToPrn(),
                            2: this.FinishedPrinting(),
                        }
                    }else {
                        tableObj = {
                            1: this.ProcessingAcceptanceToPrn(),
                            2: this.FinishedPrinting(),
                            3: this.servPrn()
                        }
                    }
                    const tableData = tableObj[reportTitle.key]
                    params.tables.push(tableData.tableList)
                    if(tableData.theScndTbl) {
                        params.tables.push(tableData.theScndTbl)
                    }
                    if(reportTitle.key !== 2) {
                        params.summaryInfoItems = tableData.basicInfo
                        params.tables.push(await this.prnAuditHst())
                    }
                    hideLoading()
                    return params
                } catch (err) {
                    console.log(err)
                    this.clientPop('err', '打印失败')
                    hideLoading()
                }
            }
            const data = await printData()
            webprintReport(data)
        },
        // 委外加工物资结算单
        ProcessingAcceptanceToPrn () {
            const basicInfo = []
            const data = this.formData
            const list = [
                ['加工单位', data.processingUnitName, false],
                ['附件', '    ' + '张', false],
                ['发票编号', data.invoiceNo, false],
                ['结算依据', data.contractBillNo, false],
                ['税率(%)', data.taxRate + '%', false],
                ['结算日期', data.settlementDate, false],
                ['不含税金额(元)', data.processCost, false],
                ['可抵扣税额(元)', data.taxAmount, false],
                ['税价合计金额(元)', data.totalAmount, false],
                ['差额(元)', data.taxDifference, false],
                ['累计结算金额(元)', data.cumulativeSettlementAmount, false],
                ['价税合计金额大写', numToChinese(Math.abs(data.totalAmount)), true],
                ['备注信息', data.remarks, true],
            ]
            list.forEach(item => {
                const obj = {
                    label: '标题',
                    value: '内容',
                    isFullRow: false, // 是否占整行
                }
                obj.label = item[0]
                obj.value = item[1]
                obj.isFullRow = item[2]
                basicInfo.push(obj)
            })
            // 加工费明细
            let newArr = this._.cloneDeep(this.jgfData)
            let lastArr = []
            newArr.forEach(item => {
                lastArr.push(item)
                if(item.children.length > 0) {
                    lastArr.push(...item.children)
                }
            })
            const tableList = {
                'tableTitle': '加工费明细',
                'tableContent': {
                    '物资类别': 'materialClassName',
                    '物资名称': 'materialName',
                    '规格': 'spec',
                    '材质': 'texture',
                    '单位': 'unit',
                    '数量': 'quantity',
                    '验收单价(元)': 'acceptancePrice',
                    '验收金额(元)': 'acceptanceAmount',
                    '结算单价(元)': 'price',
                    '结算金额(元)': 'amount',
                    '差额(元)': 'difference',
                },
                'tableData': lastArr, //表格数据
            }
            // 原物资明细
            let yaunwuziArr = this._.cloneDeep(this.ywzData)
            let rawMaterialsArr = []
            yaunwuziArr.forEach(item => {
                rawMaterialsArr.push(item)
                if(item.children.length > 0) {
                    rawMaterialsArr.push(...item.children)
                }
            })
            const theScndTbl = {
                'tableTitle': '原物资明细',
                'tableContent': {
                    '物资类别': 'materialClassName',
                    '物资名称': 'materialName',
                    '规格': 'spec',
                    '材质': 'texture',
                    '单位': 'unit',
                    '仓库': 'warehouseName',
                    '领用数量': 'receivedQuantity',
                    '冲库存数量': 'offsetInventoryQuantity',
                    '单价(元)': 'price',
                    '金额(元)': 'amount',
                },
                'tableData': rawMaterialsArr, //表格数据
            }
            return { basicInfo, tableList, theScndTbl }
        },
        // 成品物资明细
        FinishedPrinting () {
            // 表格数据
            let newArr = this._.cloneDeep(this.cpwzData)
            let lastArr = []
            newArr.forEach(item => {
                lastArr.push(item)
                if(item.children.length > 0) {
                    lastArr.push(...item.children)
                }
            })
            const tableList = {
                'tableTitle': '成品物资明细',
                'tableContent': {
                    '物资类别': 'materialClassName',
                    '物资名称': 'materialName',
                    '规格': 'spec',
                    '材质': 'texture',
                    '单位': 'unit',
                    '仓库': 'warehouseName',
                    '数量': 'quantity',
                    '成品单价(元)': 'price',
                    '金额(元)': 'amount',
                },
                'tableData': lastArr, //表格数据
            }
            return { tableList }
        },
        // 服务费
        servPrn () {
            if(this.serviceFeeData.length > 0) {
                if(this.serviceFeeList.length < 1) {
                    this.serviceFeeList = this._.cloneDeep(this.serviceFeeData)
                    return this.FmtData(this.serviceFeeList)
                }else {
                    return this.FmtData(this.serviceFeeList)
                }
            }else {
                this.clientPop('err', '服务费用无明细可打印')
                return
            }
        },
        // 格式数据
        FmtData (data) {
            // 是否相同结算单位
            const isTheSm = data.some(item =>data[0].settlementUnitId !== item.settlementUnitId)
            // 是否相同税率
            const isSmRt = data.some(item =>data[0].taxRate !== item.taxRate)
            if(isTheSm || isSmRt) {
                this.clientPop('err', '需选择相同结算单位和相同税率的数据,请先选择!')
                return
            }else {
                // 如果都是相同结算单位并且相同税率
                const obj = data.reduce((prev, c) => {
                    prev.amount += +(+c.amount).toFixed(2),
                    prev.totalAmount += +(+c.totalAmount).toFixed(2),
                    prev.taxAmount += +(+c.taxAmount).toFixed(2)
                    return prev
                }, { amount: 0, totalAmount: 0, taxAmount: 0, })
                obj.settlementUnitName = data[0].settlementUnitName
                obj.contractBillNo = data[0].contractBillNo
                obj.taxRate = data[0].taxRate
                return this.servPrnSelectFn(obj)
            }
        },
        servPrnSelectFn (obj) {
            const basicInfo = []
            const data = this.formData
            const list = [
                ['服务单位', obj.settlementUnitName, false],
                ['附件', '    ' + '张', false],
                ['结算依据', obj.contractBillNo, false],
                ['结算日期', data.settlementDate, false],
                ['不含税金额(元)', obj.amount, false],
                ['税率(%)', obj.taxRate + '%', false],
                ['可抵扣税额(元)', obj.taxAmount, false],
                ['税价合计金额(元)', obj.totalAmount, false],
                // ['差额(元)', data.totalAmount, false],
                ['税价合计金额大写', numToChinese(Math.abs(obj.totalAmount)), true],
                ['备注信息', data.remarks, true],
            ]
            list.forEach(item => {
                const obj = {
                    label: '标题',
                    value: '内容',
                    isFullRow: false, // 是否占整行
                }
                obj.label = item[0]
                obj.value = item[1]
                obj.isFullRow = item[2]
                basicInfo.push(obj)
            })
            // 表格数据
            const tableList = {
                'tableTitle': '服务费明细',
                'tableContent': {
                    '结算单位': 'settlementUnitName',
                    '清单名称': 'contractDtlName',
                    '发票编号': 'invoiceNo',
                    '数量': 'quantity',
                    '单价(元)': 'price',
                    '金额': 'amount',
                    '税率': 'taxRate',
                    '税额': 'taxAmount',
                    '税额合计': 'totalAmount',
                },
                'tableData': this.serviceFeeList, //表格数据
            }
            return { basicInfo, tableList }
        },
        // 审核历史
        async prnAuditHst () {
            const historyList = {
                'tableTitle': '审核历史',
                'tableContent': {
                    '审核级次': 'unitName',
                    '审核人': 'assignUser',
                    '审核人岗位': 'userTitle',
                    '通知时间': 'notifyTime',
                    '审核时间': 'completeTime',
                    '审核意见': 'opinion',
                },
                'tableData': this.shenheArr, //表格数据
            }
            return historyList
        },

        // 保存基本信息
        updateBaseInfo () {
            this.formData.processCost = +this.jiagongfei // 加工费
            this.formData.totalAmount = +this.shuijiaheji //税价合计
            this.formData.taxAmount = +this.shuie // 税额
            this.isEndSettle == true
                ? (this.formData.isEndSettle = 1)
                : (this.formData.isEndSettle = 0)
            this.isOffsetAdvancePayment == true
                ? (this.formData.isOffsetAdvancePayment = 1)
                : (this.formData.isOffsetAdvancePayment = 0)
            this.$refs.rulesBaseRef.validate(async valid => {
                if (valid) {
                    await auditRequest.updatejgrk(this.formData)
                } else {
                    return
                }
            })
        },
        // 保存加工费
        async saveProcessingFee () {
            await auditRequest.updatejgf(this.jgfData)
            await this.getProcessingFee()
        },
        // 保存成品物资
        async saveFinishedProduct () {
            await auditRequest.updatecpwz(this.cpwzData)
            await this.getFinishedGoods()
        },
        // 保存原物资
        async saveRawMaterials () {
            await auditRequest.updateywz(this.ywzData)
            this.getRawMaterials()
        },
        // 保存服务费用
        async saveServiceFee () {
            await auditRequest.updatefwfy(this.serviceFeeData)
            await this.getServiceFee()
        },
        // 保存保证金
        async saveMargin () {
            await auditRequest.udatebzj(this.fhbzjtableData)
            await this.getMargin()
        },

        zkbzjchange (row) {
            row.changeType === 1 ? (row.changeType = 1) : (row.changeType = 2)
            row.currentTotalAmount =
                row.previousTotalAmount - 0 + (row.amount - 0)
        },
        returnBondBlur (row) {
            row.changeType === 1 ? (row.changeType = 1) : (row.changeType = 2)
        },
        fhbzjchange (row) {
            row.changeType === 1 ? (row.changeType = 1) : (row.changeType = 2)
        },
        fhbzjAdd () {
            selectDataClient({
                SelectServiceToken:
                    '/materialsettle/purchaseSettlement/listUnreturnAmountForSelect', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id(注意：是上一次已选中的id，不是要传的参数，如果第一次选，则传[])
                InitParamsStr: '0', // 接口参数(name为模拟参数)
                Title: '选择返还保证金' // 标题
            }).then(() => {
                // this.setSelectedInfo(val)
                // openAppClient('/showSelectedData', '选择结果', function () {
                // })
            })
        },
        shuilvgaiian () {
            if (this.formData.taxRate > 0) {
                if (this.formData.taxRate < 100) {
                    return
                } else {
                    this.formData.taxRate = 0
                    showErrorPop('税率只能在0-100之间,请检查！')
                }
            } else {
                this.formData.taxRate = 0
                showErrorPop('税率只能是数字或者正数,请检查！')
            }
        },
        shuilvgaiian2 (row) {
            if (row.unsettledQuantity - 0 < row.quantity - 0) {
                // alert(row.unsettledQuantity)
                row.quantity = +row.unsettledQuantity
                showErrorPop('不能超过未结算数量,请检查！')
                return
            }
            if (row.quantity > 0) {
                const str = row.quantity + ''
                if (str.length > 1) {
                    if (str[0] == 0 || str[0] == '0') {
                        row.quantity = 0
                        showErrorPop('不能已0开头,请检查！')
                    }
                } else {
                    return
                }
            } else {
                row.quantity = 0
                showErrorPop('结算数量只能是数字或者正数,请检查！')
            }
        },
        addzkbzj () {
            let data = JSON.parse(localStorage.getItem('vuex'))
            const orgid = data.userInfo.orgInfo.orgId
            selectDataClient({
                SelectServiceToken: '/subcontract/basicSettingsBond/getBond', // 客户端对应方法名
                IsSingleMode: false, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id(注意：是上一次已选中的id，不是要传的参数，如果第一次选，则传[])
                InitParamsStr: JSON.stringify({
                    orgId: orgid,
                    contractCategoryName: '物资采购合同'
                }), // 接口参数(name为模拟参数)
                Title: '选择暂扣保证金' // 标题
            }).then(val => {
                //保存用户选择返回数据到store
                // this.zkbzjtableData = val
                for (let i = 0; i < val.length; i++) {
                    this.zkbzjtableData.push({
                        returnDepositName: val[i].name, //保证金名称
                        returnDepositId: val[i].billId, //保证金id
                        amount: 0, //暂扣保证金
                        previousTotalAmount: 0, //截止上期先固定写0
                        currentTotalAmount: 0, //截止本期
                        remarks: '', //备注
                        returnDepositType: 1 //1代表暂扣 2代表返还
                    })
                }
            })
        },
        async demi1 () {
            let jgfquery = []
            for (let i = 0; i < this.cpwzData.length; i++) {
                for (let j = 0; j < this.cpwzData[i].children.length; j++) {
                    jgfquery.push(this.cpwzData[i].children[j].dtlId)
                }
            }
            console.log(jgfquery)
            let jgfjk = await auditRequest.getjgflist({
                billId: this.billId,
                finishedGoodsDtlIds: jgfquery
            })
            console.log(jgfjk)
        },
        gaibian2 (obj, type) {
            console.log('333')
            if (type == '冲库存数量') {
                if (obj.offsetInventoryQuantity > obj.unsettledQuantity) {
                    obj.offsetInventoryQuantity = obj.unsettledQuantity
                    showErrorPop('冲库存数量不能超过未结算数量')
                    return
                }
                obj.price =
                    (obj.amount / obj.offsetInventoryQuantity).toFixed(2) - 0
            }
        },
        gaibian (obj, type) {
            // settledAmount金额 settledQuantity结算数量 settledPrice单价 taxDifference税额差价
            // quantity结算数量  amount加工费
            console.log(type)
            console.log(obj)
            // obj.price = obj.amount / obj.quantity
            console.log('数量', obj.quantity)
            console.log('加工费', obj.amount)

            if (obj.amount - 0 > -99999999 && obj.quantity - 0 > -9999999) {
                console.log('进入判断')
                // amount 加工费   quantity 结算数量
                obj.price =
                    ((obj.amount - 0) / (obj.quantity - 0)).toFixed(2) - 0
                if (obj.price !== obj.acceptancePrice) {
                    console.log('不一样了！！！！', obj)
                    let item = {}
                    for (let i = 0; i < this.jgfData.length; i++) {
                        for (
                            let j = 0;
                            j < this.jgfData[i].children.length;
                            j++
                        ) {
                            if (this.jgfData[i].children[j].uuid == obj.uuid) {
                                item = this.jgfData[i]
                            }
                        }
                    }
                    console.log('item222', item)
                    const ishave = this.cjlbData.filter(i => {
                        return item.uuid == i.uuid
                    })
                    console.log('ishave', ishave)
                    if (ishave.length == 0) {
                        this.cjlbData.push(item)
                    }
                } else {
                    console.log('一样了的时候')
                }

                console.log('eee', this.cpwzData)
                for (let i = 0; i < this.cpwzData.length; i++) {
                    console.log('进入1')
                    for (let j = 0; j < this.cpwzData[i].children.length; j++) {
                        //先暂时用物资类别的名称来判断
                        const row = this.cpwzData[i].children[j]
                        if (row.materialName == obj.materialName) {
                            const item = this.cpwzData[i].children[j]
                            console.log(item, 'item')
                            console.log('我1')
                            item.price =
                                (
                                    obj.quantity * obj.price +
                                    item.amount
                                ).toFixed(2) - 0
                            item.amount =
                                (item.price / item.quantity).toFixed(2) - 0
                        }
                    }
                }
            } else {
                if (!obj.amount == Number) {
                    obj.price = 0
                } else if (!obj.quantity == Number) {
                    obj.price = 0
                }
            }
        },
        addmx () {
            console.log('新增')
        },
        shuieheji (row) {
            if (
                row.taxRate - 0 > -999999 &&
                row.taxRate != 0 &&
                row.amount - 0 > -999999 &&
                row.amount != 0
            ) {
                row.taxAmount = (row.amount * (row.taxRate / 100)).toFixed(4)
                row.totalAmount = row.taxAmount - 0 + (row.amount - 0)
            }
        },
        //选择借支人员
        danjia (row, type) {
            console.log(row)
            console.log(type)
            if (
                row.amount - 0 > -999999 &&
                row.amount != 0 &&
                row.quantity - 0 > -999999 &&
                row.quantity != 0
            ) {
                row.price = (row.amount / row.quantity).toFixed(4)
                if (row.taxRate == 0) {
                    row.totalAmount = row.price
                }
            }
            // if(type == '数量') {

            //     if((row.amount - 0) > -999999 && row.amount != 0 && (row.quantity - 0) > -999999  && row.quantity != 0) {
            //         row.price = (row.amount / row.quantity).toFixed(4)
            //     }
            // }else{
            //     if((row.quantity - 0) > -999999  && row.quantity != 0) {
            //         row.price = (row.amount / row.quantity).toFixed(4)
            //     }
            // }
        },
        xzjzry () {
            //  borrowerName: '', //借资人员名称
            //  borrowerId: '', //借资人员id 不显示
            selectDataClient({
                SelectServiceToken: '/hr/user/getUserUnderOrgPage', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id
                Title: '借支人员选择' // 标题
            }).then(val => {
                // this.setSelectedInfo(val)
                // openAppClient('/showSelectedData', '选择结果', function () {
                // })
                if (val.length > 0) {
                    this.formData.borrowerName = val[0].userName
                    this.form.borrowerId = val[0].userId
                }
            })
        },
        //选择冲销对象
        xzcxdx () {
            // 弹窗选择数据
            selectDataClient({
                SelectServiceToken:
                    '/facilityconnect/lease/receive/plan/contract/receive', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id(注意：是上一次已选中的id，不是要传的参数，如果第一次选，则传[])
                InitParamsStr: JSON.stringify({ name: '' }), // 接口参数(name为模拟参数)
                Title: '选择机构用户' // 标题
            }).then(val => {
                // 保存用户选择返回数据到store
                // this.setSelectedInfo(val)
                // // 客户端弹窗预览结果
                // // 参数依次为: 打开页面地址、标题、回调函数
                // openAppClient('/showSelectedData', '选择结果', function () {
                //     // alert('关闭后回调')
                // })
                if (val.length > 0) {
                    this.formData.reversalObjectNumber = val[0].leaseUnit
                    this.form.reversalObjectId = val[0].leaseUnitId
                }
            })
        },
        chakand () {
            console.log(this.Thewas)
            console.log(this.Thewas != 'add')
        },
        inputchanger1 (e) {
            console.log('111', e)
            if (e == 2 || e == 3) {
                this.formData.isPersonalBorrowing = false
                this.formData.personalBorrowing = 0
                this.formData.reversalObjectNumber = ''
                this.formData.reversalObjectId = ''
                this.formData.borrowerName = ''
                this.formData.borrowerId = ''
            }
        },
        inputchanger2 (e) {
            console.log('111', e)
            if (e == false) {
                this.formData.personalBorrowing = 0
                this.formData.reversalObjectNumber = ''
                this.formData.reversalObjectId = ''
                this.formData.borrowerName = ''
                this.formData.borrowerId = ''
            }
        },
        inputchanger3 (e) {
            if (e == false) {
                this.formData.offsetAdvancePayment = 0
            }
        },
        tableRowClassNameF ({ row }) {
            if (row.changeType === -1) {
                return 'warning-row'
            }
            return ''
        },
        serviceFeeDelete (row, index) {
            this.clientPop('info', this.oneDeleteErr, () => {
                if (row.dtlId) {
                    this.$set(row, 'changeType', -1)
                } else {
                    this.serviceFeeData.splice(index, 1)
                }
                row.amount = 0
                row.totalAmount = 0
            })
        },
        async contractDialog (row, index) {
            let contracted = {
                contractId: row.contractBillId,
                contractType: row.contractBillType || 0
            }
            let res = await auditRequest.getContract(
                { orgid: this.orgId, contractId: this.formData.contractBillId },
                contracted
            )
            let result
            // 如果选择的是合同并且合同下有清单,则需带入合同下的清单
            if (res.list && res.list.length > 0) {
                result = res.list.map(item => {
                    return {
                        amount: null,
                        billId: this.billId || '',
                        changeType: 1,
                        contractBillId: res.contractId,
                        contractBillNo: res.contractNumber,
                        contractBillType: res.contractType,
                        contractDtlId: item.detailedId,
                        contractDtlName: item.name,
                        contractQuantity: item.quantity,
                        dtlId: '',
                        invoiceNo: '',
                        price: null,
                        quantity: item.quantity,
                        settlementUnitId: res.secondPartyId,
                        settlementUnitName: res.secondPartyName,
                        sourceServiceFeeDtlId: '',
                        taxAmount: 0,
                        taxRate: res.taxRate,
                        totalAmount: 0
                    }
                })
                let _arr = []
                result.forEach(item => {
                    const shouldPush = this.serviceFeeData.every(
                        it => item.contractDtlId !== it.contractDtlId
                    )
                    if (shouldPush) {
                        _arr.push(item)
                    } else {
                        // 找到了清单ID相同
                        const repeatArr = this.serviceFeeData.filter(
                            i => item.contractDtlId === i.contractDtlId
                        )
                        const noPush = repeatArr.some(
                            _its => _its.changeType !== -1
                        )
                        if (!noPush) {
                            _arr.push(item)
                        }
                    }
                })
                if (_arr.length !== 0) {
                    this.serviceFeeData.splice(index, 1, ..._arr)
                }
            } else {
                // 如果选择的合同没有清单
                result = {
                    amount: null,
                    billId: this.billId,
                    changeType: 1,
                    contractBillId: res.contractId,
                    contractBillNo: res.contractNumber,
                    contractBillType: res.contractType,
                    contractDtlId: '',
                    contractDtlName: '',
                    dtlId: '',
                    invoiceNo: '',
                    price: null,
                    quantity: null,
                    settlementUnitId: res.secondPartyId,
                    settlementUnitName: res.secondPartyName,
                    sourceServiceFeeDtlId: '',
                    taxAmount: 0,
                    taxRate: res.taxRate,
                    totalAmount: 0
                }
                const shouldPush = this.serviceFeeData.every(
                    it => it.contractBillId !== result.contractBillId
                )
                if (shouldPush) {
                    this.serviceFeeData.splice(index, 1, result)
                } else {
                    const repeatArr = this.serviceFeeData.filter(
                        i => i.contractBillId === result.contractBillId
                    )
                    const noPush = repeatArr.some(
                        _its => _its.changeType !== -1
                    )
                    if (!noPush) {
                        this.serviceFeeData.splice(index, 1, result)
                    }
                }
            }
        },
        async billingUnitDialog (row, index) {
            let res = await auditRequest.getBillingUnit(
                this.jsdwData,
                row.settlementUnitId
            )
            // async getServeList () { // 弹窗好了,需删除这行
            //     let res = await request.getServeList(this.billingUnitQuery) // 弹窗好了,需删除这行
            let result = {
                amount: null,
                billId: this.billId,
                changeType: 1,
                contractBillId: '',
                contractBillNo: '',
                contractBillType: 0,
                contractDtlId: '',
                contractDtlName: '',
                contractQuantity: '',
                dtlId: '',
                invoiceNo: '',
                price: null,
                quantity: null,
                settlementUnitId: res.id,
                settlementUnitName: res.outerName,
                taxAmount: 0,
                taxRate: 0,
                totalAmount: 0
            }
            const shouldPush = this.serviceFeeData.every(
                it => it.settlementUnitId !== result.settlementUnitId
            )
            if (shouldPush) {
                this.serviceFeeData.splice(index, 1, result)
            } else {
                const repeatArr = this.serviceFeeData.filter(
                    i => i.settlementUnitId === result.settlementUnitId
                )
                const noPush = repeatArr.some(_its => _its.changeType !== -1)
                if (!noPush) {
                    this.serviceFeeData.splice(index, 1, result)
                }
            }
            this.formData.freight = this.serviceFeeData.reduce(
                (pre, c) => (pre += +c.amount || 0),
                0
            )
        },
        serviceFeeAdd () {
            // this.serviceFeeData.push(this.serviceFeeRow)
            // 弹窗选择数据
            this.serviceFeeData.push({
                amount: 0, //金额元
                billId: '',
                changeType: 1,
                contractBillId: '',
                contractBillNo: '',
                contractBillType: 0,
                contractDtlId: '',
                contractDtlName: '',
                dtlId: '',
                invoiceNo: '',
                price: 0, //单价元
                quantity: 0, //数量
                settlementUnitId: '',
                settlementUnitName: '',
                taxAmount: 0, //税额元
                taxRate: 0, //税率%
                totalAmount: 0 // 税价合计
            })
        },
        // 复选框选中的数据
        serviceFeeSelect (selection) {
            this.serviceFeeList = selection
        },
        xzry () {
            selectDataClient({
                SelectServiceToken: '/hr/user/getUserUnderOrgPage', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id
                Title: '人员选择' // 标题
            }).then(val => {
                if (val.length > 0) {
                    this.$set(
                        this.formData,
                        'acceptancePersonnelName',
                        val[0].userName
                    )
                    this.$set(
                        this.formData,
                        'acceptancePersonnelId',
                        val[0].userId
                    )
                }
            })
        },
        xzjsmx () {
            selectDataClient({
                SelectServiceToken:
                    '/materialsettle/processingAcceptance/listUnsettleFinishedGoodsForSelect', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id(注意：是上一次已选中的id，不是要传的参数，如果第一次选，则传[])
                InitParamsStr: '', // 接口参数(name为模拟参数)
                Title: '选择结算明细' // 标题
            }).then(async result => {
                // this.setSelectedInfo(result)
                // openAppClient('/showSelectedData', '数组')
                if (result.length < 1) {
                    this.clientPop('err', '请选择验收明细！')
                    return
                }
                // 先判断所选择的数据是否都是同一个合同下的,如果不是同一个合同直接提示并且不执行后面操作
                let res = result.filter(item => item.parentId != 0)
                // this.setSelectedInfo(res)
                // openAppClient('/showSelectedData', '数组')
                let isSameContract = res.some(
                    item => res[0].contractId !== item.contractId
                )
                if (isSameContract) {
                    this.clientPop('err', '只能选择相同合同的物资,请重新选择!')
                    return
                }
                let data = res.find(item => item.parentId != 0)
                // 不能选择不同的合同做验收
                if (
                    this.formData.contractBillId &&
                    this.formData.contractBillId !== data.contractId
                ) {
                    this.clientPop('err', '只能选择相同合同的物资,请重新选择!')
                    return
                }
                if (
                    this.cpwzData.length < 1 &&
                    !this.formData.processingUnitId
                ) {
                    this.basicDataFun(data)
                    this.jgfData = this.processingFun(res) // 加工费
                    this.cpwzData = this.settlementFun(res) // 成品物资
                } else if (this.formData.contractBillId !== data.contractId) {
                    // 如果选择的源单不同,需提示用户,如果确定则覆盖原有结算明细和基本信息
                    this.clientPop(
                        'info',
                        '当前选择源单与原有源单不同,若点击确定,原有基本信息和加工费,成品物资将被覆盖!',
                        () => {
                            this.jgdwChange() // 将原数组的changeType置为1或删除
                            this.basicDataFun(data) // 带出基本信息某些数据
                            this.settlementPush(res) // 将成品物资数据添加至表格
                            this.processingFeePush(res) // 将加工费数据添加至表格
                        }
                    )
                } else {
                    this.basicDataFun(data)
                    this.settlementPush(res)
                    this.processingFeePush(res)
                }
            })
        },
        // 将选择的验收数据带入到基本信息
        basicDataFun (res) {
            this.$set(
                this.formData,
                'processingUnitName',
                res.processingUnitName
            ) //加工单位 processingUnitName 合同 contractNam
            this.$set(this.formData, 'processingUnitId', res.processingUnitId)

            this.$set(this.formData, 'contractName', res.contractName) //合同 contractNam
            this.$set(this.formData, 'contractBillId', res.contractId)
            this.$set(this.formData, 'contractBillNo', res.contractNo)

            this.$set(this.formData, 'acceptanceBillId', res.billId) // 验收id
            this.$set(this.formData, 'acceptanceBillNo', res.billNo) // 验收编号
            // baseCurName

            this.$set(this.formData, 'taxRate', res.taxRate)
            // formData.taxRate
            this.$set(this.formData, 'quantity', res.unsettledQuantity)
            // taxRate

            this.$set(this.formData, 'currency', res.currency)
            this.$set(this.formData, 'baseCurName', res.baseCurName)
            //    formData.baseCurName
            if (res.sourceOfRawMaterials == 1) {
                this.$set(this.formData, 'materialSource', '购买')
            } else {
                this.$set(this.formData, 'materialSource', '自有')
            }
        },
        // 成品物资处理弹窗选择数据的格式
        settlementFun (res) {
            const newArr = []
            let obj = {}
            res.forEach(async item => {
                if (item.materialClassName && item.materialClassId) {
                    const topClassName = item.materialClassName.split('/')[0]
                    const topClassId = item.materialClassId.split('/')[0]
                    obj = {
                        topClassId,
                        topClassName,
                        customId: topClassId,
                        materialClassId: topClassId,
                        materialClassName: topClassName,
                        uuid: getUuid(),
                        totalAmount: null,
                        totalQuantity: null,
                        children: []
                    }
                    if (newArr.length < 1) {
                        newArr.push(obj)
                    } else {
                        let isParent = newArr.every(
                            itm => itm.topClassId !== topClassId
                        )
                        if (isParent) {
                            newArr.push(obj)
                        }
                    }

                    newArr.forEach(async its => {
                        if (
                            its.materialClassId ===
                            item.materialClassId.split('/')[0]
                        ) {
                            its.children.push({
                                uuid: getUuid(),
                                customId: getUuid(),
                                amortizationMonth: item.amortizationMonth, // 摊销月
                                apportionedFreight: item.apportionedFreight, // 分摊运费
                                amount: '', // 金额
                                billId: this.billId, //	验收ID
                                changeType: 1, //变更类型
                                dtlId: '', //验收明细ID
                                materialClassId: item.materialClassId
                                    .split('/')
                                    .slice(1)
                                    .join('/'), //物资类别id
                                materialClassName: item.materialClassName
                                    .split('/')
                                    .slice(1)
                                    .join('/'), // 物资类别名称
                                materialId: item.materialId, //物资id
                                materialName: item.materialName, //物资名称
                                price: '', // 成品单价
                                quantity: item.unsettledQuantity, //结算数量
                                sourceDtlId: item.dtlId, //源单明细id
                                sourceFinishedGoodsDtlId: '', //原成品明细id
                                spec: item.spec, //规格型号
                                texture: item.texture, //材质
                                totalAmortizationRatio:
                                    item.totalAmortizationRatio, // 总摊销比例(%)
                                unit: item.unit, //计量单位
                                unsettledQuantity: item.unsettledQuantity, //	未结算数量
                                warehouseId: item.warehouseId, //仓库id
                                warehouseName: item.warehouseName //仓库名称
                            })
                        }
                        // 统计小计
                        const count = +its.children
                            .reduce((prev, c) => (prev += +c.amount || 0), 0)
                            .toFixed(2)
                        its.materialName = `金额小计： ${count}`
                    })
                }
            })
            return newArr
        },
        // 加工数据格式处理
        processingFun (res) {
            const newArr = []
            let obj = {}
            res.forEach(async item => {
                if (item.materialClassName && item.materialClassId) {
                    const topClassName = item.materialClassName.split('/')[0]
                    const topClassId = item.materialClassId.split('/')[0]
                    obj = {
                        topClassId,
                        topClassName,
                        customId: topClassId,
                        materialClassId: topClassId,
                        materialClassName: topClassName,
                        uuid: getUuid(),
                        totalAmount: null,
                        totalQuantity: null,
                        children: []
                    }
                    if (newArr.length < 1) {
                        newArr.push(obj)
                    } else {
                        let isParent = newArr.every(
                            itm => itm.topClassId !== topClassId
                        )
                        if (isParent) {
                            newArr.push(obj)
                        }
                    }

                    newArr.forEach(async its => {
                        if (
                            its.materialClassId ===
                            item.materialClassId.split('/')[0]
                        ) {
                            its.children.push({
                                uuid: getUuid(),
                                customId: getUuid(),
                                acceptancePrice: item.price, // 验收单价
                                acceptanceTaxAmount: item.taxAmount, // 验收税额
                                amount: '', // 加工费金额
                                billId: this.billId, //	验收ID
                                changeType: 1, //变更类型
                                dtlId: '', //验收明细ID
                                materialClassId: item.materialClassId
                                    .split('/')
                                    .slice(1)
                                    .join('/'), //物资类别id
                                materialClassName: item.materialClassName
                                    .split('/')
                                    .slice(1)
                                    .join('/'), // 物资类别名称
                                materialId: item.materialId, //物资id
                                materialName: item.materialName, //物资名称
                                price: '', // 加工单价
                                quantity: item.unsettledQuantity, //结算数量
                                sourceDtlId: item.dtlId, //源单明细id
                                sourceProcessCostDtlId: '', //原成品明细id
                                spec: item.spec, //规格型号
                                taxAmount: item.taxAmount, // 分摊税额
                                taxDifference: '', // 税额差额
                                texture: item.texture, //材质
                                unit: item.unit, //计量单位
                                unsettledQuantity: item.unsettledQuantity, //	未结算数量
                                warehouseId: item.warehouseId, //仓库id
                                warehouseName: item.warehouseName //仓库名称
                            })
                        }
                        // 统计小计
                        const count = +its.children
                            .reduce((prev, c) => (prev += +c.amount || 0), 0)
                            .toFixed(2)
                        its.materialName = `金额小计： ${count}`
                    })
                }
            })
            return newArr
        },
        // 如果成品物资明细的原数组中有数据,需要做判断是否能再次添加数据
        settlementPush (res) {
            let newArr = this.settlementFun(res)
            newArr.forEach(item => {
                const topClassIdRp = this.cpwzData.every(
                    itm => itm.topClassId != item.topClassId
                )
                // 遍历当前选择数据的每一项父级id是否存在于原有数组中,如果没有,则直接添加
                if (topClassIdRp) {
                    this.cpwzData.push(item)
                } else {
                    // 如果数组中的父级id一样,则返回一样的那一项的父级数据
                    const target = this.cpwzData.find(
                        its => its.topClassId == item.topClassId
                    )
                    // 给这条父级数据的children里面添加子级
                    item.children.forEach(it => {
                        // =========相同物资id,但是验收明细id不一样时直接添加,如果物资id一样,验收明细id一样,还需要看changType是否为-1==========
                        // 如果当前父级的子级中没有物资id相同的,则直接添加
                        const materialIdRp = target.children.every(
                            _it => _it.materialId != it.materialId
                        )
                        if (materialIdRp) {
                            target.children.push(it)
                        } else {
                            // ==================相同物资id,但是changType为-1时======================
                            // 遍历出所有子级id一样的
                            const _target = target.children.filter(
                                i => i.materialId == it.materialId
                            )
                            // 如果当前遍历的子项存在于原数组,但是changeTpye等于-1说明已经删除,那还是可以重新添加进入的,changeType不等于-1的,不做操作;如果遍历完了都是等于-1的,才添加
                            const noPush = _target.some(
                                _i => _i.changeType !== -1
                            )
                            if (!noPush) {
                                target.children.push(it)
                            }
                        }
                    })
                }
            })
        },
        // 加工费是否能继续添加数据进表格
        processingFeePush (res) {
            let newArr = this.processingFun(res)
            newArr.forEach(item => {
                const topClassIdRp = this.jgfData.every(
                    itm => itm.topClassId != item.topClassId
                )
                // 遍历当前选择数据的每一项父级id是否存在于原有数组中,如果没有,则直接添加
                if (topClassIdRp) {
                    this.jgfData.push(item)
                } else {
                    // 如果数组中的父级id一样,则返回一样的那一项的父级数据
                    const target = this.jgfData.find(
                        its => its.topClassId == item.topClassId
                    )
                    // 给这条父级数据的children里面添加子级
                    item.children.forEach(it => {
                        // =========相同物资id,但是验收明细id不一样时直接添加,如果物资id一样,验收明细id一样,还需要看changType是否为-1==========
                        // 如果当前父级的子级中没有物资id相同的,则直接添加
                        const materialIdRp = target.children.every(
                            _it => _it.materialId != it.materialId
                        )
                        if (materialIdRp) {
                            target.children.push(it)
                        } else {
                            // ==================相同物资id,但是changType为-1时======================
                            // 遍历出所有子级id一样的
                            const _target = target.children.filter(
                                i => i.materialId == it.materialId
                            )
                            // 如果当前遍历的子项存在于原数组,但是changeTpye等于-1说明已经删除,那还是可以重新添加进入的,changeType不等于-1的,不做操作;如果遍历完了都是等于-1的,才添加
                            const noPush = _target.some(
                                _i => _i.changeType !== -1
                            )
                            if (!noPush) {
                                target.children.push(it)
                            }
                        }
                    })
                }
            })
        },
        // 业务类型变化
        businessTypeChange () {
            this.formData.processingUnitName = ''
            this.formData.processingUnitId = ''
            this.formData.contractName = ''
            this.formData.contractBillId = ''
            this.formData.contractBillNo = ''
            this.formData.acceptanceBillId = ''
            this.formData.acceptanceBillNo = ''
            this.formData.taxRate = ''
            this.formData.quantity = ''
            this.formData.currency = ''
            this.formData.baseCurName = ''
            this.formData.taxDifference = 0
            this.selectStocked = '选择库存'
            this.inStockList = []
            this.jgdwChange()
        },
        // 如果业务类型变化或者选择的是不同合同,需对原有基本信息和结算明细进行处理
        jgdwChange () {
            // 成品物资
            for (let i = 0; i < this.cpwzData.length; i++) {
                for (let m = 0; m < this.cpwzData[i]['children'].length; m++) {
                    if (this.cpwzData[i]['children'][m]['dtlId']) {
                        this.$set(
                            this.cpwzData[i]['children'][m],
                            'changeType',
                            -1
                        )
                        this.$set(this.cpwzData[i]['children'][m], 'amount', 0)
                    } else {
                        this.cpwzData[i]['children'].splice(m, 1)
                        m--
                    }
                }
            }

            //    加工费
            for (let i = 0; i < this.jgfData.length; i++) {
                for (let m = 0; m < this.jgfData[i]['children'].length; m++) {
                    if (this.jgfData[i]['children'][m]['dtlId']) {
                        this.$set(
                            this.jgfData[i]['children'][m],
                            'changeType',
                            -1
                        )
                        this.$set(this.jgfData[i]['children'][m], 'amount', 0)
                        this.$set(
                            this.jgfData[i]['children'][m],
                            'taxDifference',
                            0
                        )
                    } else {
                        this.jgfData[i]['children'].splice(m, 1)
                        m--
                    }
                }
            }
            this.formData.processCost = 0

            // 原物资
            for (let i = 0; i < this.ywzData.length; i++) {
                for (let m = 0; m < this.ywzData[i]['children'].length; m++) {
                    if (this.ywzData[i]['children'][m]['dtlId']) {
                        this.$set(
                            this.ywzData[i]['children'][m],
                            'changeType',
                            -1
                        )
                        this.$set(this.ywzData[i]['children'][m], 'amount', 0)
                    } else {
                        this.ywzData[i]['children'].splice(m, 1)
                        m--
                    }
                }
            }
        },
        // 选择原物资
        async selectStock (obj1) {
            this.selectStocked = obj1.materialName
            this.selectStockQuery.unitId = this.formData.processingUnitId
            // let data = await processingRequest.selectStock(
            //     this.selectStockQuery
            // )
            // let obj = {}
            // data.forEach(item => {
            //     obj = {
            //         topClassId: obj1.materialId,
            //         topClassName: obj1.materialName,
            //         materialClassId: obj1.materialId,
            //         materialClassName: obj1.materialName,
            //         uuid: getUuid(),
            //         totalAmount: null,
            //         totalQuantity: null,
            //         children: [],
            //         isChecked: false,
            //     }
            //     if (this.ywzData.length < 1) {
            //         this.ywzData.push(obj)
            //     } else {
            //         let isPush = this.ywzData.every(
            //             i => i.topClassId !== obj1.materialId
            //         )
            //         if (isPush) {
            //             this.ywzData.push(obj)
            //         }
            //     }
            //     this.ywzData.forEach(its => {
            //         let result = {
            //             uuid: getUuid(),
            //             customId: getUuid(),
            //             amount: 0, // 金额
            //             billId: this.billid, //	验收ID
            //             changeType: 1, //变更类型
            //             dtlId: '', //原物资明细id
            //             finishedGoodsDtlId: obj1.dtlId,
            //             materialClassId: item.materialClassId, //物资类别id
            //             materialClassName: item.materialClassName, // 物资类别名称
            //             materialId: item.materialId, //物资id
            //             materialName: item.materialName, //物资名称
            //             offsetInventoryQuantity: '', // 冲库存数量
            //             price: '', // 采购单价
            //             receivedQuantity: item.quantity, // 领用数量
            //             sourceMaterialsDtlId: '', // 原结算单-原物资明细id
            //             spec: item.spec, //规格型号
            //             texture: item.texture, //材质
            //             unit: item.unit, //计量单位
            //             warehouseId: item.warehouseId, //仓库id
            //             warehouseName: item.warehouseName,
            //             parentId: its.topClassId,
            //         }
            //         if(its.topClassId === obj1.materialId) {
            //             if (its.children.length < 1) {
            //                 // 如果没有子级,直接添加
            //                 its.children.push(result)
            //             } else  {
            //                 // 如果已经有子级了,如果有没有一样的子级,没有则添加,有还需要判断changeType为-1且changeType没有其他值的情况才添加
            //                 const isPush = its.children.every(
            //                     m => m.materialId !== result.materialId
            //                 )
            //                 if (isPush) {
            //                     its.children.push(result)
            //                 } else {
            //                     const sameArr = its.children.filter(
            //                         n => n.materialId === result.materialId
            //                     )
            //                     const noPush = sameArr.some(
            //                         i => i.changeType !== -1
            //                     )
            //                     if (!noPush) {
            //                         its.children.push(result)
            //                     }
            //                 }
            //             }
            //         }

            //         // 统计小计
            //         const count = +its.children
            //             .reduce((prev, c) => (prev += +c.amount || 0), 0)
            //             .toFixed(2)
            //         its.materialName = `金额小计： ${count}`
            //     })
            // })
        },
        rawMaterialsDeleteClick () {},

        //取消
        handleClose () {
            this.$router.replace('/machiningmentList')
        },
        onChangeTab (e) {
            const height  = $('#' + e.name).offset().top
            $.scrollTo(height - this.topHeight, 500)
            this.clickId = e.name //记录每次点击的id
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
        },
        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight () {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                if (document.getElementById('evaluateCon')) {
                    const lastConHeight =
                        document.getElementById('evaluateCon').offsetHeight
                    console.log('lastConHeight: ', lastConHeight)
                    this.lastConHeight = lastConHeight
                    console.log('this.lastConHeight', this.lastConHeight)
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },
        tableRowClassName ({ row }) {
            if (row.changeType === -1) {
                return 'warning-row'
            }
            if (row.children) {
                if (row.children.length < 1) {
                    return 'warning-row'
                } else {
                    let isDel = row.children.every(it => it.changeType === -1)
                    if (isDel) {
                        return 'warning-row'
                    }
                }
            }
            return ''
        },

    },
    computed: {
        ...mapState({
            options: state => state.contract.ctClassify,
            popConfirm: 'popConfirm',
            popStatus: 'popStatus',
            userInfo: state => state.userInfo,
            currencyForm: state => state.equip.equipData.currencyForm, //币种
            state: state => state.equip.equipData.state //通用流程状态
        }),

        jiagongfei () {
            // if(this.formData.processCost == 0) {
            if (this.jgfData.length > 0 && this.formData.taxRate > 0) {
                let num = 0
                for (let i = 0; i < this.jgfData.length; i++) {
                    for (let j = 0; j < this.jgfData[i].children.length; j++) {
                        num +=
                            +(this.jgfData[i].children[j].amount - 0).toFixed(
                                2
                            ) || 0
                    }
                }
                return num
            } else {
                return 0
            }
            // }else{
            //     return this.formData.processCost
            // }
        },
        shuijiaheji () {
            // if(this.formData.totalAmount == 0) {
            if (this.jiagongfei > 0) {
                return +(+this.jiagongfei + +this.shuie).toFixed(2)
            } else {
                return 0
            }
            // }else{
            //     return this.formData.totalAmount
            // }
        },
        shuie () {
            // taxAmount
            // if(this.formData.taxAmount == 0) {
            if (this.jiagongfei > 0 && this.formData.taxRate > 0) {
                return +(
                    this.jiagongfei *
                    (this.formData.taxRate / 100)
                ).toFixed(2)
            } else {
                return 0
            }
            // }else{
            //     return this.formData.taxAmount
            // }
        },
        jiesuanjine () {
            // settledAmount金额 settledQuantity结算数量 settledPrice单价 taxDifference税额差价
            // if(this.formData.amount == 0) {
            if (this.wzlbTableData.length > 0) {
                let num = 0
                for (let i = 0; i < this.wzlbTableData.length; i++) {
                    if (this.wzlbTableData[i].children.length > 0) {
                        for (
                            let j = 0;
                            j < this.wzlbTableData[i].children.length;
                            j++
                        ) {
                            num +=
                                this.wzlbTableData[i].children[j]
                                    .settledAmount - 0 || 0
                        }
                    }
                }
                return num
            } else {
                return 0
            }
            // }else{
            //     return this.formData.amount
            // }
        },
        // my ↑
        yunshufuwufeiyong () {
            if (this.freight != 0) {
                if (this.serviceFeeData.length > 0) {
                    let num = 0
                    for (let i = 0; i < this.serviceFeeData.length; i++) {
                        num += this.serviceFeeData[i].totalAmount
                    }
                    return num
                } else {
                    return 0
                }
            } else {
                return 0
            }
        },

        judgeRoute () {
            if (this.$route.path.includes('Add')) {
                return false
            }
            return true
        },
        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 72 - this.lastConHeight
        },
        attachId () {
            return this.billId
        },

        // 红单状态
        redBillStateFun () {
            let redState = ''
            switch (this.formData.redBillState) {
            case 0:
                redState = '冲销中'
                break
            case 1:
                redState = '冲销中'
                break
            case 2:
                redState = '已冲销'
                break
            case 3:
                redState = '红单'
                break
            }
            return redState
        }
    },

    mounted () {
        // 获取最后一个内容区域的高度，计算底部空白
        this.getLastConHeight()

        // 保存所有tabName

        const arr = [
            'baseInfo',
            [
                'planDetail',
                'materialDetails',
                'technicalParameter',
                'technicalParameter2'
            ],
            'fwfy',
            'bzj',
            'cjlb',
            'accessory',
            'auditHistory'
        ]
        let $idsTop = []
        window.addEventListener('scroll', () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            //当点击的tab有子tab时做滚动逻辑
            if (this.clickTabFlag && arr.find(x => x === this.clickId)) {
                this.childTabClass = '' //无子tab时清空tab的类名
                return
            }

            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    let itemTop
                    let arr
                    if (item instanceof Array) {
                        const prevHeight = document.getElementById(
                            item[0]
                        ).offsetHeight //因这里一个选项有两个表格，需获取前一个表格的高度进行计算
                        arr = item.map((x, i) => {
                            if (i === 0) {
                                return document.getElementById(x).offsetTop
                            } else {
                                return (
                                    document.getElementById(x).offsetTop +
                                    prevHeight +
                                    document.getElementById(item[0]).offsetTop
                                )
                            }
                        })
                        return arr
                    } else {
                        itemTop = document.getElementById(item).offsetTop
                        return itemTop
                    }
                })
            }
            const scrollTop =
                document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            let curLocalChild = 1
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                if ($idsTop[i] instanceof Array) {
                    let item = $idsTop[i]
                    for (let lenth = item.length, j = lenth - 1; j >= 1; j--) {
                        let itemChild = $idsTop[i][j]
                        if (scrollTop + 1 >= itemChild) {
                            curLocalChild = j
                            break
                        }
                    }
                    if (scrollTop + 1 >= item[0]) {
                        curLocal = i
                        break
                    }
                } else {
                    let item = $idsTop[i]
                    if (scrollTop + 1 >= item) {
                        curLocal = i
                        break
                    }
                }
            }
            // 设置对应tabName
            if (arr[curLocal] instanceof Array) {
                this.tabsName = arr[curLocal][0]
                this.tabsNameChild = arr[curLocal][curLocalChild]
            } else {
                this.tabsName = arr[curLocal]
            }
            // //动态改变二级选项卡类名
            // arr.forEach((item, index) => {
            //     if (item instanceof Array) {
            //         let tabNavHeight = document.querySelector('.childTab .el-tabs__nav')
            //             ? document.querySelector('.childTab .el-tabs__nav').offsetHeight
            //             : 0
            //         if (scrollTop + 1 >= $idsTop[index + 1] - tabNavHeight) {
            //             this.childTabClass = 'childTab2'
            //         } else if (scrollTop <= $idsTop[index][1]) {
            //             this.childTabClass = ''
            //         } else {
            //             this.childTabClass = 'childTab1'
            //         }
            //     }
            // })
        })

        this.screenWidth = document.documentElement.clientWidth - this.topHeight
        this.screenHeight = document.documentElement.clientHeight - this.topHeight
        window.addEventListener('resize', () => {
            this.screenWidth = document.documentElement.clientWidth - this.topHeight
            this.screenHeight = document.documentElement.clientHeight - this.topHeight
            $idsTop = arr.map(item => {
                let itemTop
                let arr
                if (item instanceof Array) {
                    const prevHeight = document.getElementById(
                        item[0]
                    ).offsetHeight //因这里一个选项有两个表格，需获取前一个表格的高度进行计算
                    arr = item.map((x, i) => {
                        if (i === 0) {
                            return document.getElementById(x).offsetTop
                        } else {
                            return (
                                document.getElementById(x).offsetTop +
                                prevHeight +
                                document.getElementById(item[0]).offsetTop
                            )
                        }
                    })
                    return arr
                } else {
                    itemTop = document.getElementById(item).offsetTop
                    return itemTop
                }
            })
        })
    }
}
</script>

<style lang="scss" scoped>
.lll {
    width: 100%;
    height: 30px;
    line-height: 30px;
    background: #f2f2f2;
    padding-right: 20px;
    padding-left: 20px;
}
.buttons {
    left: 0;
}
.e-form {
    margin-bottom: 80px;
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}

.e-table {
    background: #fff;
}
::v-deep.el-table .warning-row {
    display: none;
}
// ::v-deep.el-table__body-wrapper::-webkit-scrollbar{
//      width: 6px !important; // 横向滚动条
//     height: 10px !important// 纵向滚动条
// }

::v-deep .el-table__body-wrapper::-webkit-scrollbar {
    width: 6px; // 横向滚动条
    height: 10px; // 纵向滚动条
}
// 滚动条的滑块
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: 5px;
}
::v-deep.el-table .warning-row {
    display: none;
}
.el-tab-pane {
    margin-left: -10px;
}
.childTab {
    ::v-deep .el-tabs__header {
        position: absolute !important;
    }
    ::v-deep .el-tabs__content {
        padding: 0 0 0 20px !important;
    }
}
.childTab1 {
    ::v-deep .el-tabs__header {
        position: absolute !important;
        .el-tabs__nav-scroll {
            position: relative;
            .el-tabs__nav {
                position: fixed;
                top: 0;
                width: 190px;
            }
        }
    }
}
.childTab2 {
    ::v-deep .el-tabs__header {
        position: absolute !important;
        .el-tabs__nav-scroll {
            position: relative;
            .el-tabs__nav {
                position: absolute;
                bottom: 0;
                width: 100%;
            }
        }
    }
}
</style>
